import Message from './message';
import i18next from './i18next/i18n';
const { t } = i18next;
const initErrorResponse = (code: string | number) => {
	switch (code) {
		case '1001':
			Message.warning(t('user-no-exist'));
			break;
		case '1103':
			Message.warning(t('relogin-wrong-user'));
			break;
		case '1104':
			Message.warning(t('relogin-invalid-account'));
			break;
		default:
			Message.warning(t('service-error'));
			break;
	}
};

const loginErrorResponse = (code: string | number) => {
	switch (code) {
		case '3008':
			Message.warning(t('request-timeout'));
			break;
		case '3009':
			Message.warning(t('network-recovering'));
			break;
		case '3001':
			break;
		default:
			Message.warning(t('login-failed'));
			break;
	}
};

const onDropErrorResponse = (code: string | number) => {
	switch (code) {
		case 403:
			Message.warning(t('relogin-other-login'));
			break;
		case 401:
			Message.warning(t('relogin-kickoff'));
			break;
		case 402:
			Message.warning(t('relogin-network-error'));
			break;
		case 404:
			Message.warning(t('relogin-network-broken'));
			break;
		case 405:
			Message.warning(t('relogin-network-reconnect'));
			break;
		default:
			break;
	}
};

const readyErrorResponse = (code: string | number) => {
	switch (code) {
		case '3006':
			Message.warning(t('send-message-error'));
			break;
		case '3007':
			Message.warning(t('send-message-timeout'));
			break;
		case '3009':
			Message.warning(t('reconnecting'));
			break;
		default:
			Message.warning(t('ready-failed'));
			break;
	}
};

const unReadyErrorResponse = (code: string | number) => {
	switch (code) {
		case '3006':
			Message.warning(t('send-message-error'));
			break;
		case '3007':
			Message.warning(t('send-message-timeout'));
			break;
		case '3009':
			Message.warning(t('network-reconnecting'));
			break;
		default:
			Message.warning(t('cancel-ready-failed'));
			break;
	}
};

const appointErrorResponse = (code: string | number) => {
	switch (code) {
		case '3006':
			Message.warning(t('send-message-error'));
			break;
		case '3007':
			Message.warning(t('send-message-timeout'));
			break;
		case '3009':
			Message.warning(t('network-reconnecting'));
			break;
		default:
			Message.warning(t('break-book-failed'));
			break;
	}
};

const checkInErrorResponse = (code: string | number) => {
	switch (code) {
		case '3006':
			Message.warning(t('send-message-error'));
			break;
		case '3007':
			Message.warning(t('send-message-timeout'));
			break;
		case '3009':
			Message.warning(t('network-reconnecting'));
			break;
		default:
			Message.warning(t('check-in-group-failed'));
			break;
	}
};

const checkOutErrorResponse = (code: string | number) => {
	switch (code) {
		case '3006':
			Message.warning(t('send-message-error'));
			break;
		case '3007':
			Message.warning(t('send-message-timeout'));
			break;
		case '3009':
			Message.warning(t('network-reconnecting'));
			break;
		default:
			Message.warning(t('check-out-group-failed'));
			break;
	}
};

const answerErrorResponse = (code: string | number) => {
	switch (code) {
		case '60022':
			Message.warning(t('device-request-reject'));
			break;
		case '60023':
			Message.warning(t('device-start-failed'));
			break;
		case '60024':
			Message.warning(t('device-start-failed'));
			break;
		case '60025':
			Message.warning(t('device-resolution-not-match'));
			break;
		case '1017':
			Message.warning(t('client-leaved-error'));
			break;
		case '5008':
			Message.warning(t('session-end-error'));
			break;
		case '5006':
			Message.warning(t('answer-call-error'));
			break;
		default:
			break;
	}
};

const ccsErrorResponse = (code: string | number) => {
	switch (code) {
		case 103:
			Message.warning(t('network-broken-session-end'));
			break;
		case 105:
			Message.warning(t('network-fluctuation-retry-failed'));
			break;
		default:
			break;
	}
};

const ConnectStatusErrorResponse = (status: string) => {
	switch (status) {
		case 'connect':
			Message.normal(t('connect-success'));
			break;
		case 'reconnecting':
			Message.warning(t('network-try-to-recover'));
			break;
		case 'reconnect_failed':
			Message.warning(t('reconnect-failed'));
			break;
	}
};

const systemErrorResponse = (code: string | number, errorData: string) => {
	let customerSubscribeId = sessionStorage.getItem('customerSubscribeId');
	switch (code) {
		case 1006:
			Message.warning(t('relogin-network-error'));
			break;
		case 1007:
			Message.warning(t('network-message-error-whether-hangup'));
			break;
		case 1005:
			Message.warning(t('network-media-error-whether-hangup'));
			break;
		case 1004:
			if (errorData === customerSubscribeId) {
				Message.warning(t('client-video-disconnect'));
			}
			break;
		default:
			break;
	}
};

const transferErrorResponse = (error: any, type: string, options?: any) => {
	let agent = options?.agentId || '';
	switch (error.code) {
		case '404':
			Message.warning(type === 'transfer' ? t('no-seats-available-transfer-error') : t('agent-unable-to-answer'));
			break;
		case '406':
			Message.warning(type === 'transfer' ? t('transfer-failed-not-work-day') : t('invite-failed-not-work-day'));
			break;
		case '407':
			Message.warning(type === 'transfer' ? t('transfer-failed-not-work-time') : t('invite-failed-not-work-time'));
			break;
		case '401':
			Message.warning(t('transfer-timeout-wait-retry'));
			break;
		case '408':
			Message.warning(t('business-scenarios-not-available'));
			break;
		case '402':
			switch (error.waitingCode) {
				case '1001':
					Message.warning(t('agent-not-available'));
					break;
				case '1002':
					Message.warning(t('agent-not-login'));
					break;
				case '1003':
					Message.warning(t('transfer-agent-not-available'));
					break;
				case '1004':
					Message.warning(t('transfer-agent-session-disconnect'));
					break;
				default:
					Message.warning(t('assigning-agents'));
					break;
			}
			break;
		case '412':
			if (type === 'transfer') {
				Message.warning(t('not-transfer-ai-agent-multiple-clients'));
			} else {
				Message.warning(t('not-invite-ai-agent-multiple-clients'));
			}
			break;
		case '413':
			if (type === 'transfer') {
				Message.warning(t('reject-join-session'));
			} else {
				Message.warning(t('not-invite'));
			}
			break;
		case '414':
			Message.warning(t('agent-busy-no-success-invite'));
			break;
		case '400':
			Message.warning(t('no-seats-available-transfer-error'));
			break;
		case '418':
			Message.warning(t('scenario-roles-notMatched'));
			break;
		case '420':
			Message.warning(t('group-not-match'));
			break;
		case '421':
			Message.warning(t('label-not-match'));
			break;
		case '422':
			if (type === 'transfer') {
				Message.warning(`${t('agent')} <${agent}> ${t('not-bind-nowBizScenario')}, ${t('transfer-failed')}`);
			} else {
				Message.warning(`${t('agent')} <${agent}> ${t('not-bind-nowBizScenario')}, ${t('invite-failed')}`);
			}

			break;
		case '423':
			if (type === 'transfer') {
				Message.warning(`${t('agent')} <${agent}> ${t('not-chekin-nowBizScenario')}, ${t('transfer-failed')}`);
			} else {
				Message.warning(`${t('agent')} <${agent}> ${t('not-chekin-nowBizScenario')}, ${t('invite-failed')}`);
			}

			break;
		case '601':
			Message.warning(t('audio-video-recording-completed'));
			break;
		case '602':
			Message.warning(t('audio-video-recording-waited'));
			break;
		case '603':
			Message.warning(t('audio-video-recordingIn-progress'));
			break;
		case '604':
			Message.warning(t('audio-video-rerecordingIn-progress'));
			break;
		case '605':
			if (type === 'transfer') {
				Message.warning(t('transfer-call-exists'));
			} else {
				Message.warning(t('invite-call-exists'));
			}
			break;
		case '606':
			if (type === 'transfer') {
				Message.warning(t('multiple-call-exists-transfer'));
			} else {
				Message.warning(t('multiple-call-exists-invite'));
			}
			break;
		case '607':
			Message.warning(t('notAllow-transferIn-multiple'));
			break;
		case '5006':
			Message.warning(type === 'transfer' ? t('send-transfer-failed') : t('send-invite-failed'));
			break;
		case '5008':
			Message.warning(type === 'transfer' ? t('send-transfer-failed') : t('send-invite-failed'));
			break;
		case '5009':
			Message.warning(type === 'transfer' ? t('reconnect-transfer-error') : t('reconnect-invite-error'));
			break;
		case '5010':
			Message.warning(type === 'transfer' ? t('send-transfer-failed') : t('send-invite-failed'));
			break;
		case '5011':
			Message.warning(type === 'transfer' ? t('send-transfer-failed') : t('send-invite-failed'));
			break;
		default:
			Message.warning(t('transfer-timeout-wait-retry'));
			break;
	}
};

export {
	initErrorResponse,
	loginErrorResponse,
	onDropErrorResponse,
	readyErrorResponse,
	unReadyErrorResponse,
	appointErrorResponse,
	checkInErrorResponse,
	checkOutErrorResponse,
	answerErrorResponse,
	ccsErrorResponse,
	ConnectStatusErrorResponse,
	systemErrorResponse,
	transferErrorResponse
};
